<?php
defined('IN_MAIN') or exit('Invalid Access!');

function get_total_group_downline($uid, $date_from='', $date_to=''){
global $vars;
$db=$vars['db'];

$total_downline=0;
$upline=$uid;
if($upline){
	do{
	 $t=@mysql_num_rows($r=mysql_query("select id from $db->users where matrix_upline in ($upline)")) or 0;
	 $upline='';
	 for($i=0;$i<$t;$i++){
	  $downline=mysql_fetch_assoc($r);
	  $upline.=($upline? "," : "").$downline['id'];
	  $all_downlines.=$upline.',';
	 }
	 $total_downline+=$t;
	}while($upline);
	if($date_from && $date_to){
		$all_downlines = rtrim($all_downlines, ',');
		$total_downline = @mysql_result(mysql_query($sql="select count(*) from $db->users where id in ($all_downlines) and cdate>='$date_from' and cdate<='$date_to'"), 0) or 0;
		if(!$total_downline){
			$total_downline = 0;
		}
	}
}

return $total_downline;
}
?>